package com.java110.community.cmd.repair;

import com.alibaba.fastjson.JSONObject;
import com.java110.community.cmd.community.UpdateCommunityCmd;
import com.java110.core.annotation.Java110Cmd;
import com.java110.core.context.ICmdDataFlowContext;
import com.java110.core.event.cmd.Cmd;
import com.java110.core.event.cmd.CmdEvent;
import com.java110.core.log.LoggerFactory;
import com.java110.dto.repair.RepairSettingDto;
import com.java110.intf.community.IRepairSettingInnerServiceSMO;
import com.java110.po.repair.RepairSettingPo;
import com.java110.utils.exception.CmdException;
import com.java110.utils.util.BeanConvertUtil;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.ParseException;


/**
 * 保存保修配置
 * @author 陈立高
 * @date 2024/03/17
 */
@Java110Cmd(serviceCode = "repair.saveRepairSetting")
public class SaveRepairSettingCmd extends Cmd {
    private static Logger logger = LoggerFactory.getLogger(UpdateCommunityCmd.class);
    @Autowired
    private IRepairSettingInnerServiceSMO repairSettingInnerServiceSMO;

    @Override
    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {

    }

    @Override
    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException, ParseException {
        logger.info("保存保修配置请求入参：{}", reqJson.toJSONString());
        //保存保修配置
        RepairSettingDto repairSettingDto = BeanConvertUtil.covertBean(reqJson, RepairSettingDto.class);
        String repairSettingType = repairSettingDto.getRepairSettingType();
        switch (repairSettingType){
            case "100"://社区
                repairSettingDto.setRepairSettingTypeName("保洁单");
                break;
            case "200"://社区
                repairSettingDto.setRepairSettingTypeName("保修单");
                break;
            default:
                break;
        }
        String repairWay = repairSettingDto.getRepairWay();
        switch (repairWay){
            case "100"://社区
                repairSettingDto.setRepairWayName("抢单");
                break;
            case "200"://社区
                repairSettingDto.setRepairWayName("指派");
                break;
            case "300"://社区
                repairSettingDto.setRepairWayName("轮训");
                break;
            default:
                break;
        }
        String returnVisitFlag = repairSettingDto.getReturnVisitFlag();
        switch (returnVisitFlag){
            case "001"://社区
                repairSettingDto.setReturnVisitFlagName("不回访");
                break;
            case "002"://社区
                repairSettingDto.setReturnVisitFlagName("已评价不回访");
                break;
            case "003"://社区
                repairSettingDto.setReturnVisitFlagName("回访");
                break;
            default:
                break;
        }
        repairSettingInnerServiceSMO.saveRepairSetting(repairSettingDto);
    }
}
